package com.star.jersey.mybatisplus.base.core.contract;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * 分页数据结构
 *
 * @param <T>
 */
public class Page<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    // 总记录数
    private int total;
    // 列表数据
    private List<T> list = Collections.emptyList();

    public Page(List<T> list, int total) {
        this.list = list;
        this.total = total;
    }

    public Page(List<T> list, long total) {
        this.list = list;
        this.total = (int) total;
    }

    public boolean isEmpty() {
        return this.list == null || this.list.isEmpty();
    }

    public boolean isNotEmpty() {
        return !this.isEmpty();
    }

    public static <T> Page<T> succeed(List<T> list, int total) {
        return new Page(list, total);
    }

    public static <T> Page<T> empty() {
        return new Page(Collections.emptyList(), 0);
    }

    public int getTotal() {
        return this.total;
    }

    public List<T> getList() {
        return this.list;
    }

}